import request, { REQUEST_TYPE } from "@/api/request.js";
const BaseUrl = process.env.NODE_ENV === 'development' ? '/configService' : '/dataSearch/configService'
const REGION_URL = '/regionServer'
export function getChildrenRegionListByCode(parentCode) {
  return request({
    url: '/region/getChildrenRegionListByCode',
    method: "get",
    data: { parentCode: parentCode },
  });
}

export function getShapeByCode(code) {
  return request({
    url: '/region/getShapeByCode',
    method: "get",
    data:{ code: code },
  });
}

/**
 * 上传shp文件，获取wkt空间范围，只支持压缩包形式
 */
export function getShapeByFile(file){
  return request({
    url: `${baseServer}/rsmis-scdm-data-provider-service/uploadShapFile`,
    data: file,
    method: REQUEST_TYPE.POST_JSON
  })
}
const configService='configServer'
const baseServer='/baseServer'
/**
 * 获取分组样式的值
 */
export function getGroups(groupType,nodeType){
  const data={
    groupType:`GROUP_TYPE_${groupType}`,
    nodeType
  }
  return request({
    url: `${configService}/config/node/group`,
    data,
    method: REQUEST_TYPE.POST_JSON
  })
}

/**
 * 获取节点
 * */

export function getNodes(){
  return request({
    url: `${configService}/config/node`,
    method: REQUEST_TYPE.GET
  })
}
/**
 *根据节点id获取参数
 * */
export function getFieldById(id){
  return request({
    baseURL: BaseUrl,
    url: `${baseServer}/rsmis-scdm-data-provider-service/config/node/querySchema/${id}`,
    method: REQUEST_TYPE.GET
  })
}


/**
 * 获取厂商资源配置
 * */
export function getSupplier(nodeId){
  return request({
    url: `${baseServer}/rsmis-scdm-data-provider-service/data/supplier/${nodeId}`,
    method: REQUEST_TYPE.GET
  })
}
export function dataOrder(data){
  return request({
    baseURL: BaseUrl,
    url: '/dataOrder/subscribe',
    method: REQUEST_TYPE.POST_JSON,
    data
  })
}

/**
 * 获取行政区的范围
 * */
export async function getRegionShape(code) {
  return await request({
    url: `${REGION_URL}/region/queryNationRegionWkt?code=${code}`,
    method: REQUEST_TYPE.GET
  })
}

